package com.github.maojx0630.easy.translate.translate.impl;

import com.github.maojx0630.easy.translate.translate.impl.dict.TranslateField;
import com.github.maojx0630.easy.translate.translate.impl.dict.ValueCache;
import com.github.maojx0630.easy.translate.translate.TranslateHandle;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;

/**
 * @author 毛家兴
 * @since 2024-06-19 14:31
 */
public class DictHandleImpl implements TranslateHandle<TranslateField> {

  private final ValueCache valueCache;

  public DictHandleImpl(ValueCache valueCache) {
    this.valueCache = valueCache;
  }

  @Override
  public Object getTranslateValue(TranslateField ann, String value, Field field) {
    return valueCache.get(value, ann);
  }

  @Override
  public List<String> getTranslateField(TranslateField translateField, String s, Field field) {
    List<String> list=new ArrayList<>();
    for (String alias : translateField.alias()) {
      list.add(field.getName() + alias);
    }
    return list;
  }
}
